package com.mid;

/**
 * Created by Lxk on 2019/5/18.
 */
public class Solution238 {

    public static int[] productExceptSelf(int[] nums) {
        int[] res = new int[nums.length];
        res[0] = nums[0];
        for(int i = 1;i < nums.length; i++){
            res[i] = nums[i]*res[i-1];
        }
        int temp = 1;
        for(int i = nums.length-1;i > 0;i--){
            res[i] = res[i-1]*temp;
            temp *= nums[i];
        }
        res[0] = temp;
        return res;
    }

    public static void main(String[] args) {
        int[]arr = {1,2,3,4};
        System.out.println(productExceptSelf(arr));
    }

}
